package com.salesmanager.core.business.customer.model;

import com.salesmanager.core.business.common.model.audit.AuditListener;
import com.salesmanager.core.business.generic.model.SalesManagerEntity;

import javax.persistence.*;
import java.util.Date;

@Entity
@EntityListeners(value = AuditListener.class)
@Table(name = "CUSTOMER_AUTHS",uniqueConstraints = {
        @UniqueConstraint(columnNames = {"CUSTOMER_ID","IDENTITY_TYPE"},name = "UNI_CI_IT")
})
public class CustomerAuths extends SalesManagerEntity<Long, CustomerAuths> {

    @Id
    @Column(name = "CUSTOMER_AUTHS_ID", unique=true, nullable=false)
    @TableGenerator(name = "TABLE_GEN", table = "SM_SEQUENCER", pkColumnName = "SEQ_NAME", valueColumnName = "SEQ_COUNT",
            pkColumnValue = "CUSTOMER_AUTH_SEQ_NEXT_VAL",initialValue = 100000, allocationSize = 50)
    @GeneratedValue(strategy = GenerationType.TABLE, generator = "TABLE_GEN")
    private Long id;

    @ManyToOne(fetch = FetchType.EAGER,cascade = { CascadeType.PERSIST,
            CascadeType.MERGE, CascadeType.REFRESH })
    @JoinColumn(name = "CUSTOMER_ID",nullable = false)
    private Customer customer;

    /**
     * 账号类型 1:手机号 2:微信
     */
    @Column(name = "IDENTITY_TYPE")
    private Integer identityType;

    /**
     * 账号 根据账号类型填写不同的值
     */
    @Column(name = "IDENTIFIER")
    private String identifier;

    /**
     * 凭证  密码或token
     */
    @Column(name = "CERTIFICATE")
    private String certificate;

    /**
     * 三方登陆后的唯一ID
     */
    @Column(name = "OPEN_ID")
    private String openId;

    /**
     * 创建时间
     */
    @Column(name = "CREATE_TIME")
    private Date createTime;

    /**
     * 修改时间
     */
    @Column(name = "MODIFY_TIME")
    private Date modifyTime;

    /**
     * 状态 1:有效 0:无效
     */
    @Column(name = "STATUS")
    private Integer status;


    @Override
    public Long getId() {
        return this.id;
    }

    @Override
    public void setId(Long id) {
        this.id = id;
    }


    public Customer getCustomer() {
        return customer;
    }

    public void setCustomer(Customer customer) {
        this.customer = customer;
    }

    public Integer getIdentityType() {
        return identityType;
    }

    public void setIdentityType(Integer identityType) {
        this.identityType = identityType;
    }

    public String getIdentifier() {
        return identifier;
    }

    public void setIdentifier(String identifier) {
        this.identifier = identifier;
    }

    public String getCertificate() {
        return certificate;
    }

    public void setCertificate(String certificate) {
        this.certificate = certificate;
    }

    public String getOpenId() {
        return openId;
    }

    public void setOpenId(String openId) {
        this.openId = openId;
    }

    public Date getCreateTime() {
        return createTime;
    }

    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }

    public Date getModifyTime() {
        return modifyTime;
    }

    public void setModifyTime(Date modifyTime) {
        this.modifyTime = modifyTime;
    }

    public Integer getStatus() {
        return status;
    }

    public void setStatus(Integer status) {
        this.status = status;
    }
}